
import datetime
import os
import shutil
from common.config import cfg
BACKUP_DIR = cfg['backup']['dst_dir']
DBPATH = cfg['backup']['src_path']
def backup_database():
    # Generate a backup file name with a timestamp
    backup_file_name = f'backup_{datetime.datetime.now().strftime("%Y%m%d%H%M%S")}.db'
    # Path to the backup directory
    # Create the backup directory if it doesn't exist
    if not os.path.exists(BACKUP_DIR):
        os.makedirs(BACKUP_DIR)
    # Full path to the backup file
    backup_file_path = os.path.join(BACKUP_DIR, backup_file_name)
    # Copy the database file to the backup location
    shutil.copy2(DBPATH, backup_file_path)
    print(f"Backup created: {backup_file_path}")